/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package th.stripes.action;

import able.stripes.JSP;
import com.google.inject.Inject;
import com.oas.thit._this.xsd.THISBaseDataElementBody;
import com.oas.thit._this.hajj.xsd.HajjResponseBody;
import com.oas.thit._this.flight.xsd.FlightScheduleResponseBody;
import com.oas.thit._this.hajj.xsd.HajjOfferLetterResponseBody;
import com.oas.thit.hajj.xsd.RequestBody;
import com.oas.thit.hajj.groupslip.xsd.GroupSlipResponseBody;
import com.oas.thit.hajj.groupslip.xsd.GroupSlipResponseLineItem;
import com.oas.thit.hajj.hjcheck.xsd.HjCheckRequestBody;
import com.oas.thit.hajj.hjcheck.xsd.HjCheckResponseBody;
import com.oas.thit.hajj.query.xsd.RegistrationQueryRequestBody;
import com.oas.thit.hajj.query.xsd.RegistrationQueryResponseBody;
import com.oas.thit.hajj.registration.xsd.RegistrationRequestBody;
import com.oas.thit.hajj.registration.xsd.RegistrationResponseBody;
import com.oas.thit._this.profile.depositor.xsd.DepositorProfileResponseBody;
import com.oas.thit.xmlmessage.xsd.Header;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.action.DefaultHandler;
import th.model.Pengguna;
import th.model.PermohonanMaklumat;
import th.model.PermohonanMaklumatKeluarga;
import th.model.PermohonanMaklumatWaris;
import th.model.KodUrusan;
import th.model.KodPekerjaan;
import th.model.KodSektorPekerjaan;
import th.model.KodStatus;
import th.model.KodStatusHaji;
import th.model.KodHubungan;
import th.model.KodNegeri;
import th.model.KodTahapPengajian;
import th.model.KodKahwin;
import th.model.KodUrusan;
import th.model.KodWarganegara;
import th.model.Haji;
import th.model.Poskod;
import th.model.PermohonanMaklumatKumpulan;
import th.model.Kumpulan;
import th.model.PusatKos;
import th.model.SlipPendaftaran;
import th.stripes.BaseActionBean;
import th.stripes.config.AuthRequired;
import java.util.*;
import java.util.logging.Level;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBElement;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sourceforge.stripes.action.Before;
import th.manager.UserManager;
import th.manager.HajjManager;
import th.model.SuratTawaran;
import th.model.InfoAudit;
import th.dao.KodUrusanDAO;
import th.dao.KodBandarDAO;
import th.dao.KodNegeriDAO;
import th.dao.KodWarganegaraDAO;
import th.dao.KodKahwinDAO;
import th.dao.KodTahapPengajianDAO;
import th.dao.KodSektorPekerjaanDAO;
import th.dao.KodPekerjaanDAO;
import th.dao.KodHubunganDAO;
import th.dao.KodStatusDAO;
import th.dao.KodStatusHajiDAO;
import th.dao.PusatKosDAO;
import th.dao.PoskodDAO;
import th.stripes.webservice.WebServiceUtil;
import th.stripes.util.ListUtil;
import th.stripes.BaseActionBean;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.controller.LifecycleStage;
import org.apache.log4j.Logger;
import th.config.ableContextListener;
import th.dao.KodJantinaDAO;
import th.dao.THISutilDAO;
import th.manager.ResponseManager;
import th.manager.SejarahTransaksiManager;
import th.model.Deposit;
import th.model.PilihanDestinasi;
import th.model.SejarahTransaksi;
import th.model.SuratPenerbanganJH;
import th.model.THISutil;
import th.stripes.Configuration;
import th.stripes.util.AccCheckUtil;
import th.stripes.util.DateFormatDetector;
/**
 *
 * @author ubuntu
 */

@UrlBinding("/haji")
public class HajiActionBean extends BaseActionBean{   
           
    private Pengguna pengguna;
    private Haji haji;
    private Kumpulan kumpulan;
    private Deposit deposit;
    
    private static String SUCCESSFUL = "0000";
    private static String ACCEPTED = "6000";
    private static String DECLINED = "6301";
    private static String CLOSED = "6300";
    private static String DECLINED_G = "6200";
    private static String SYSTEM_ERROR = "9999";   
    private static String INVALID_ACC_IC = "9000"; 
    private static String NO_HAJJ_OFR_RECORD = "7000";
    private static String NO_FLIGHT_SCH_RECORD = "7000";
    private static String ACCOUNT_ALREADY_REGISTRED = "7000";
    private static String UNSUCCESSFULL = "1000";
    
    
    private static String HAJ_ENQ_MSG_ID = "TPHOFRCKWD01";    
    private static String HEADER_ID_HAJ_OFFER_CHECK = "THSHOCK";
    private static String HAJ_CHK_MSG_ID = "TPHAJCHKWD01";    
    private static String HEADER_ID_HAJ_REGISTRATION_CHECK = "THSHCHK";
    private static String FLT_SCH_MSG_ID = "TPHJFLSCWD01"; 
    private static String HEADER_ID_HAJ_FLIGHT_SCH = "THSHFSC";
    private static String OFF_LTR_MSG_ID = "TPHOFRLTWD01";    
    private static String HEADER_ID_HAJ_OFFER_LTR = "THSHOLT";
    private static String HAJ_SLIP_MSG_ID = "TPHJSLIPWD01"; 
    private static String PROFILE_ENQ_MSG_ID = "TPDPPROFWD01";
    private static String HEADER_ID_HAJ_SLIP_GROUP = "THSHSLP";
    private static String HAJ_REG_QUERY_MSG_ID = "TPHAJREGWD01";  
    private static String HEADER_ID_HAJ_REGISTRATION_QUERY = "THSHQRY";
    private static String HAJ_REG_MSG_ID = "TPHAJREGWD02";  
    private static String HEADER_ID_HAJ_REGISTRATION = "THSHREG";
    private static String HEADER_ID_PROFILE_ENQUIRY = "THSDPQR";
    
    private static String KOD_URUSAN_DAFTAR = "01";
    private static String KOD_URUSAN_JAWAB = "02";
    private static String KOD_STATUS_TERIMA= "01";
    private static String KOD_STATUS_TOLAK = "02";
    private static String STATUS_TAMBAHAN_WUJUD = "A";
    private static String STATUS_TAMBAHAN_CIPTA = "C";
    private static String STATUS_TAMBAHAN_UBAH = "U";
    private static String STATUS_CREATE = "V";
    private static String STATUS_ADD = "M";
    private static String STATUS_EXIST = "E";
    private static String TAWARAN_TIADA = "7770";
    private static String TAWARAN_TERIMA = "7771";
    private static String TAWARAN_TOLAK = "7772";
    private static String TAWARAN_BATAL = "7773";

   
    @Inject private KodUrusanDAO kodUrusanDAO;
    @Inject private KodNegeriDAO kodNegeriDAO;
    @Inject private PoskodDAO poskodDAO;
    @Inject private KodKahwinDAO kodKahwinDAO;
    @Inject private KodWarganegaraDAO kodWarganegaraDAO;
    @Inject private KodTahapPengajianDAO kodTahapPengajianDAO;
    @Inject private KodSektorPekerjaanDAO kodSektorPekerjaanDAO;
    @Inject private KodPekerjaanDAO kodPekerjaanDAO;
    @Inject private KodHubunganDAO kodHubunganDAO;
    @Inject private KodStatusDAO kodStatusDAO;
    @Inject private KodStatusHajiDAO kodStatusHajiDAO;
    @Inject private PusatKosDAO pusatKosDAO;
    @Inject private THISutilDAO tHISutilDAO;
    @Inject private KodBandarDAO kodBandarDAO;
    @Inject private ListUtil listUtil;
    @Inject private WebServiceUtil webUtil;
    @Inject private ResponseManager responseManager;
    @Inject private SejarahTransaksiManager sejarahTransaksiManager;
    @Inject private Configuration conf;    
    @Inject private KodJantinaDAO kodJantinaDAO;
    private static Logger LOG = Logger.getLogger(DepositActionBean.class);
    
    @DefaultHandler
    public Resolution showMainForm() {
        return new JSP("haji/main_haji.jsp");
    }  
    
    @Before(stages={LifecycleStage.BindingAndValidation})
    public void rehydrate() {
        pengguna = getContext().getCurrentUser();        
    }
    
   //-+-+-+-+-+-+-+-+-+-+-+-+-+-SEMAK TAWARAN HAJI-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//

    public Resolution showFormSemakTawaranHaji () {        
        pengguna = getContext().getCurrentUser();
        haji = new Haji();
        if (pengguna != null) {          
            haji.setNoKp(pengguna.getNoKp());
        }
        return new JSP("haji/pertanyaan_tawaran_haji.jsp");
    }    
      
   

     public Resolution semakTawaranHaji () {
        String responseCode = "";
        DateFormat d = new SimpleDateFormat("yyyyMMdd");
          
        try { // Call Web Service Operation
            com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
            com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap12Endpoint();
            // TODO initialize WS operation arguments here
            com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();            
            
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();          
            com.oas.thit.xmlmessage.xsd.ObjectFactory objHeader = new com.oas.thit.xmlmessage.xsd.ObjectFactory();
            Header reqHead = objHeader.createHeader();
            reqHead.setMsgId( objHeader.createHeaderMsgId(HAJ_ENQ_MSG_ID));
            reqHead.setResponseCode( objHeader.createHeaderResponseCode(SUCCESSFUL) );
            
            reqHead.setTxid(objHeader.createHeaderTxid( webUtil.getHeaderID(HAJ_ENQ_MSG_ID, HEADER_ID_HAJ_OFFER_CHECK) ));
            
            JAXBElement<Header> jReqHead = objHeader.createEventHeader(reqHead);
            req.setHeader(jReqHead);            
            
            THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
            reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(haji.getNoAkaun()));
            reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(haji.getNoKp()));
            
            JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
            req.setBody(jReqBody);  
            
            com.oas.thit._this.hajj.xsd.HajjResponse result = port.hajjCheckOffer(req);
            
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            
            //if (responseCode.equals(SUCCESSFUL) || responseCode.equals(ACCEPTED) || responseCode.equals(DECLINED) || responseCode.equals(CLOSED)) {
            if (responseCode.equals(SUCCESSFUL) || responseCode.equals(ACCEPTED) || responseCode.equals(CLOSED)) {
                
                HajjResponseBody resp = result.getBody().getValue();
                    haji.setNama(resp.getTHName().getValue());
                    haji.setNoAkaun(resp.getTHAcct().getValue());
                    haji.setNoKp(resp.getTHICNo().getValue());
                    haji.setTahunTawaran(resp.getTHYear().getValue());
                    haji.setTahunTawaranHijrah(resp.getTHYearI().getValue());
                    haji.setTarikhTawaran(d.parse(resp.getTHOfferDate().getValue().trim()));
                    haji.setTarikhTutupTawaran(d.parse(resp.getTHCloseDate().getValue().trim()));
                    haji.setStatusHaji(kodStatusHajiDAO.findById(resp.getTHHajjStatus().getValue().toString().trim()));              
                    haji.setPusatKos(pusatKosDAO.findById(resp.getTHOffice().getValue().toString().trim()));
                    if(resp.getTHHajjStatus()!=null && resp.getTHHajjStatus().getValue()!=null){
                        KodStatus kodStatus = (kodStatusDAO.findById(resp.getTHHajjStatus().getValue().trim()));
                        haji.setStatusTawaran(kodStatus.getNama());
                    }                    
                    THISutil tHISutil = tHISutilDAO.findById("101");  
                    haji.setNoTelTHCC(tHISutil.getDeskripsi().toString());
                    setHaji(haji);
                    
                    if (haji.getStatusHaji() == null) {
                         return new JSP("haji/pertanyaan_tawaran_haji_detail.jsp");
                    } else if (haji.getStatusHaji().getKod().equalsIgnoreCase("G")) {
                        addSimpleMessage("TUAN / PUAN TELAH MENOLAK TAWARAN");
                        return new JSP("haji/msg.jsp");
                    } 
                    
//                    
//                    if (haji.getStatusHaji().getKod().equalsIgnoreCase("G")) {
//                        addSimpleMessage("TUAN / PUAN TELAH MENOLAK TAWARAN");
//                        return new JSP("haji/msg.jsp");
//                    } else {
//                        return new JSP("haji/pertanyaan_tawaran_haji_detail.jsp");
//                    }
                    
                   //return new JSP("haji/pertanyaan_tawaran_haji_detail.jsp");
            } else if (responseCode.equals(DECLINED)) {
                 addSimpleMessage("TUAN / PUAN SUDAH MENOLAK TAWARAN"); 
            } else if (responseCode.equals(DECLINED_G)) {
                addSimpleMessage("TUAN / PUAN TELAH MENOLAK TAWARAN");
            }else {addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_ENQ_MSG_ID));}            
        } catch (Exception ex) {
            LOG.error(ex);
            responseCode = SYSTEM_ERROR;
            addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_ENQ_MSG_ID)); 
        }
        return new JSP("haji/msg.jsp");
    }
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-JADUAL PENERBANGAN-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//    
    @AuthRequired
    public Resolution showFormSemakJadualPenerbangan () {
        haji = new Haji();
        pengguna = getContext().getCurrentUser();
        if (pengguna != null) {         
            haji.setNoKp(pengguna.getNoKp());
        }
        return new JSP("haji/jadual_penerbangan.jsp");
    }
    
    @AuthRequired
    public Resolution semakJadualPenerbangan() {
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        DateFormat format = new SimpleDateFormat("yyyyMMdd");
        
        try {
            deposit = getProfileDeposit(haji.getNoAkaun(), haji.getNoKp());
        } catch (ParseException ex) {
            java.util.logging.Logger.getLogger(HajiActionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if (deposit != null) {
            
            AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
            deposit.setNoKpDari(haji.getNoKp());
            deposit.setNoAkaunDari(haji.getNoAkaun());
            boolean check = checking.checkAcc(deposit, pengguna);

            if (!check) {
                addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
            }
        } else {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
        }
        
        try { // Call Web Service Operation
            com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
            com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap11Endpoint();
            // TODO initialize WS operation arguments here
            com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
            
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();          
            //com.oas.thit.xmlmessage.xsd.ObjectFactory objHeader = new com.oas.thit.xmlmessage.xsd.ObjectFactory();
            
            req.setHeader(webUtil.createHeader(FLT_SCH_MSG_ID, HEADER_ID_HAJ_FLIGHT_SCH) );
            
            //Header reqHead = objHeader.createHeader();
            //reqHead.setMsgId( objHeader.createHeaderMsgId(FLT_SCH_MSG_ID));
            //reqHead.setResponseCode( objHeader.createHeaderResponseCode(SUCCESSFUL) );
            
            //reqHead.setTxid(objHeader.createHeaderTxid( webUtil.getHeaderID(FLT_SCH_MSG_ID, HEADER_ID_HAJ_FLIGHT_SCH) ));
            
            //JAXBElement<Header> jReqHead = objHeader.createEventHeader(reqHead);
            //req.setHeader(jReqHead);            
            
            THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
            reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(haji.getNoAkaun()));
            reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(haji.getNoKp()));
            
            JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
            req.setBody(jReqBody);  
            
            // TODO process result here
            com.oas.thit._this.flight.xsd.FlightScheduleResponse result = port.hajjFlightSchedule(req);
            
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            
            sejarahTransaksi.setPengguna(pengguna);
            sejarahTransaksi.setTrhMasuk(new Date());
            sejarahTransaksi.setUrusan(kodUrusanDAO.findById(FLT_SCH_MSG_ID));
            sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
            sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
            sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
            
            if (responseCode.equals(SUCCESSFUL)) {
                FlightScheduleResponseBody resp = result.getBody().getValue();
                
                haji.setNama(resp.getTHName().getValue().trim());
                haji.setNoAkaun(resp.getTHAcct().getValue().trim());
                haji.setNoKp(resp.getTHICNo().getValue().trim());
                haji.setAlamat1(resp.getTHAddress1().getValue().trim());
                haji.setAlamat2(resp.getTHAddress2().getValue().trim());
                haji.setAlamat3(resp.getTHAddress3().getValue().trim());
                haji.setLaporDiriPergi(resp.getTHDepOrigin().getValue().trim());
                
                String laporDiriBalik = resp.getTHRetOrigin().getValue().trim();
                if (laporDiriBalik.equals("JED")) {
                    haji.setLaporDiriBalik("MADINATUL HUJJAJ (JEDDAH )");
                } else if (laporDiriBalik.equals("MED")) {
                    haji.setLaporDiriBalik("LAPANGAN TERBANG (MADINAH )");
                }
                //haji.setLaporDiriBalik(resp.getTHRetOrigin().getValue().trim());
                haji.setCheckInDay(resp.getTHDepCheckinDay().getValue().trim());
                haji.setCheckInPlace(resp.getTHDepCheckinPlace().getValue().trim());
                //haji.setTarikhPergi(format.parse(resp.getTHDepDate().getValue().trim()));
                //haji.setTarikhPergi(format.parse(resp.getTHDepArrivalDate().getValue().trim()));
                haji.setTarikhPergi(format.parse(resp.getTHDepCheckinDate().getValue().trim()));
                haji.setTarikhBalik(format.parse(resp.getTHRetDate().getValue().trim()));
                //add ':' between the time
//                if(resp.getTHDepSTD().getValue()!=null)
//                    haji.setMasaPergi(resp.getTHDepSTD().getValue().substring(0,2).concat(":").concat(resp.getTHDepSTD().getValue().substring(2,4)));                 
//                if(resp.getTHRetSTD().getValue() !=null)
//                    haji.setMasaBalik(resp.getTHRetSTD().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTD().getValue().substring(2,4)));                
//                if(resp.getTHDepSTA().getValue()!=null)    
//                    haji.setMasaTiba1(resp.getTHDepSTA().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTA().getValue().substring(2,4)));
//                if(resp.getTHRetSTA().getValue()!=null)    
//                    haji.setMasaTiba(resp.getTHRetSTA().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTA().getValue().substring(2,4)));
//                if(resp.getTHRetSTA().getValue() !=null)
//                    haji.setWaktuTiba(resp.getTHRetSTA().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTA().getValue().substring(2,4)));

                /*
                 * -------------------------------------------------------------------------------------------------------------------------------
                 * ---||||Start||||--- Change format to add pagi, petang siang, malam
                 * -------------------------------------------------------------------------------------------------------------------------------
                 */
                
                /*
                 * 11082015 : Change format date to 24hrs
                 */
                 SimpleDateFormat datetimeFormatter1 = new SimpleDateFormat("HH:mm");
                 
                 Date a = null;
                 Date b = null;
                 Date c = null;
                 Date d = null;
                 Date e = null;
                 Date f = null;
                 b = datetimeFormatter1.parse("11:59");
                 c = datetimeFormatter1.parse("12:59");
                 d = datetimeFormatter1.parse("18:59");
                 e = datetimeFormatter1.parse("00:00");
                 f = datetimeFormatter1.parse("06:59");
 
                /*
                 * No 1 
                 */
                if(resp.getTHDepSTD().getValue()!= null){
                   String masa = resp.getTHDepSTD().getValue().substring(0,2).concat(":").concat(resp.getTHDepSTD().getValue().substring(2,4)); 
                   //a = datetimeFormatter1.parse(resp.getTHDepSTD().getValue());
                   a = datetimeFormatter1.parse(masa);
                   if (a.compareTo(b) < 0) {
                        /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       haji.setMasaPergi(masa);
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setMasaPergi(masa);
                    } else if (a.compareTo(d) < 0) {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setMasaPergi(newMasa);
                    } else {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" MALAM");
                        haji.setMasaPergi(newMasa);
                    }
                } else {
                     haji.setMasaPergi(resp.getTHDepSTD().getValue().trim());   
                }
                
                /*
                 * No 2
                 */
                //  if(resp.getTHRetSTD().getValue() !=null){
                if(resp.getTHRetCheckinTime().getValue() !=null){
                   String masa = resp.getTHRetCheckinTime().getValue().substring(0,2).concat(":").concat(resp.getTHRetCheckinTime().getValue().substring(2,4)); 
                   //a = datetimeFormatter1.parse(resp.getTHRetSTD().getValue());
                   a = datetimeFormatter1.parse(masa);
                   if (a.compareTo(b) < 0) { 
                       /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       haji.setMasaBalik(masa);
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setMasaBalik(masa);
                    } else if (a.compareTo(d) < 0) {
                       
                        //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println(" setCheckInTimePhase1 The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setMasaBalik(newMasa);
                    } else {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("Masa Balik  (THRetCheckinTime) :The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" MALAM");
                        haji.setMasaBalik(newMasa);
                    }
                } else {
                   
                    haji.setMasaBalik(resp.getTHRetCheckinTime().getValue().trim());
                }
                
                /*
                 * No 3
                 */
                if(resp.getTHDepSTA().getValue()!=null){
                   String masa = resp.getTHDepSTA().getValue().substring(0,2).concat(":").concat(resp.getTHDepSTA().getValue().substring(2,4)); 
                   //a = datetimeFormatter1.parse(resp.getTHRetSTD().getValue());
                   a = datetimeFormatter1.parse(masa);
                   if (a.compareTo(b) < 0) {
                        /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       haji.setMasaTiba1(masa);
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setMasaTiba1(masa);
                    } else if (a.compareTo(d) < 0) {
                        
                        //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setMasaTiba1(newMasa);
                    } else {
                      //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" MALAM");
                        haji.setMasaTiba1(newMasa);
                    }
                } else {
                    haji.setMasaTiba1(resp.getTHDepSTA().getValue().trim());
                }
                /*
                 * No 4
                 */
                if(resp.getTHRetSTA().getValue()!=null){
                   String masa = resp.getTHRetSTA().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTA().getValue().substring(2,4)); 
                    //a = datetimeFormatter1.parse(resp.getTHRetSTD().getValue());
                   a = datetimeFormatter1.parse(masa);
                   if (a.compareTo(b) < 0) {
                        /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       haji.setMasaTiba(masa);
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setMasaTiba(masa);
                    } else if (a.compareTo(d) < 0) {
                         //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setMasaTiba(newMasa);
                    } else {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" MALAM");
                        haji.setMasaTiba(newMasa);
                    }
                } else {
                     haji.setMasaTiba(resp.getTHRetSTA().getValue().trim());
                }
                /*
                 * No 5
                 */
                
                if(resp.getTHRetSTA().getValue() !=null){
                   String masa = resp.getTHRetSTA().getValue().substring(0,2).concat(":").concat(resp.getTHRetSTA().getValue().substring(2,4));
                    //a = datetimeFormatter1.parse(resp.getTHRetSTD().getValue());
                   a = datetimeFormatter1.parse(masa);
                   if (a.compareTo(b) < 0) {
                        /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       haji.setWaktuTiba(masa);
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setWaktuTiba(masa);
                    } else if (a.compareTo(d) < 0) {
                        
                         //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setWaktuTiba(newMasa);
                    } else {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                       int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println("The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" MALAM");
                        haji.setWaktuTiba(newMasa);
                    }
                } else {
                    haji.setWaktuTiba(resp.getTHRetSTA().getValue().trim());
                }
                /*
                 * No 6
                 */
                //haji.setCheckInTimePhase1(resp.getTHDepCheckinTime().getValue().trim());
                if(resp.getTHDepCheckinTime().getValue() !=null){
                   String masa = resp.getTHDepCheckinTime().getValue().substring(0,2).concat(":").concat(resp.getTHDepCheckinTime().getValue().substring(2,4));
                    //a = datetimeFormatter1.parse(resp.getTHRetSTD().getValue());
                   
                   a = datetimeFormatter1.parse(masa);
                   
                   if (a.compareTo(b) < 0) {
                       /*
                        * Added in 11082015
                        * 
                        */
                       String[]hm = masa.split(":");
                       if (hm[0].equals("00")) {
                           hm[0] = "12";
                           masa = hm[0].concat(":").concat(hm[1]);
                           }
                       masa = masa.concat(" PAGI");
                       
                       if (a.compareTo(f) < 0) {
                            /**
                            * New add : 08082014
                            * Get checkInDate, then minus 1 to handle problem 
                            * waktu melapor diri yg tak lengkap
                            */
                         
                       //Day_OF_WEEK starts from 1 while array index starts from 0
                        String[] strDays = new String[] { "AHAD", "ISNIN", "SELASA", "RABU", "KHAMIS", "JUMAAT", "SABTU" };
                        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                        Calendar cal = Calendar.getInstance();
                        
                        cal.setTime(haji.getTarikhPergi());
                        //Subtract one day from current date
                        cal.add(Calendar.DATE, -1);
                        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

                        //set
                        String dateMinus = dateFormat.format(cal.getTime());
                        String dayMinus = strDays[dayOfWeek-1];
                        haji.setCheckInDateMinus1(dateMinus);
                        haji.setCheckInDayMinus1(dayMinus);
                        
                        String afterMidnite = "SELEPAS TENGAH MALAM ";
//                        String afterMidniteDetails = null;
//                        String afConcat = dayMinus.concat(dateMinus);
//                        String afConcat2 = afterMidnite.concat(afConcat);
                        //SELEPAS TENGAH MALAM AHAD20140720
                        haji.setAfterMidnite(afterMidnite);
                        System.out.println("Check in date = " + haji.getTarikhPergi());
                        System.out.println("Check in Day = " + haji.getCheckInDay());
                        //System.out.println("Day of Checkin day : " + strDays[dayOfWeek]);
                        System.out.println("Day of Checkin date, MINUS  1 : " + haji.getCheckInDateMinus1());
                        System.out.println("Check in Day, minus 1 : " + haji.getCheckInDayMinus1());
                       }
                       haji.setCheckInTimePhase1(masa);
                       
                    } else if (a.compareTo(c) < 0) {
                       masa = masa.concat(" TENGAHARI");
                       haji.setCheckInTimePhase1(masa);
                    } else if (a.compareTo(d) < 0) {
                        
                         //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                        int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println(" setCheckInTimePhase1 The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        
                        newMasa = newMasa.concat(" PETANG");
                        haji.setCheckInTimePhase1(newMasa);
                    }
                    else {
                       //new ADD
                        String[]hm = masa.split(":");
                        int h = Integer.parseInt(hm[0]);
                        int m = Integer.parseInt(hm[1]);
                       int[] hrs = {12,1,2,3,4,5,6,7,8,9,10,11};
                        int time = Integer.parseInt(hm[0]);

                        int hours = hrs[ time % 12 ];
                        int decimalNum = time / 100;
                        decimalNum *= 100;
                        int min = time - decimalNum;

                        System.out.println(" setCheckInTimePhase1 The time is: "+ hrs[ time % 12 ] + ":" + m);
                        String newMasa = hrs[ time % 12 ] + ":" + m;
                        newMasa = newMasa.concat(" MALAM");
                       haji.setCheckInTimePhase1(newMasa);
                    }
                } else {
                    haji.setCheckInTimePhase1(resp.getTHDepCheckinTime().getValue().trim());
                }
                
 
                /*
                 * -------------------------------------------------------------------------------------------------------------------------------
                 * ---||||End ||||--- Change format to add pagi, petang siang, malam
                 * -------------------------------------------------------------------------------------------------------------------------------
                 */
                
                haji.setNoPesawatPergi(resp.getTHDepFltNo().getValue().trim());
                haji.setNoPesawatBalik(resp.getTHRETFltNo().getValue().trim());
                haji.setJumlahHari(resp.getTHPilgrimDuration().getValue().trim());
                
                String destPergi = resp.getTHDepDestination().getValue().trim();
                if (destPergi.equals("MED")) {
                    haji.setDestinasiPergi("MADINAH");
                } else if (destPergi.equals("JED")) {
                    haji.setDestinasiPergi("JEDDAH");
                }
               // haji.setDestinasiPergi(resp.getTHDepDestination().getValue().trim());
                haji.setMiqatDi(resp.getTHHaramBoundary().getValue().trim());                
                haji.setDestinasiBalik(resp.getTHRetDestination().getValue().trim());
                haji.setDepFinal(resp.getTHDepFinalDest().getValue().trim());
                haji.setRetFinal(resp.getTHRetFinalDest().getValue().trim());
                haji.setNoKt(resp.getTHKTNo().getValue().trim());
                if(resp.getTHPoskod().getValue()!=null){
                        Poskod poskod = poskodDAO.findById(resp.getTHPoskod().getValue().trim());
                        haji.setPoskod( poskod.getPoskod());
                        haji.setPoskodDeskripsi(poskod.getNama());
                    } 
                
                String offAdd1 = resp.getTHOfficeAddress1().getValue().toString().trim();
                String offAdd2 = resp.getTHOfficeAddress2().getValue().toString().trim();
                String offAdd3 = resp.getTHOfficeAddress3().getValue().toString().trim();
              
                if (offAdd1.isEmpty() == false) {
                    offAdd1 = offAdd1.concat(", ");
                }
                if (offAdd2.isEmpty() == false) {
                    offAdd2 = offAdd2.concat(", ");
                }
                if (offAdd3.isEmpty() == false) {
                    offAdd3 = offAdd3.concat(", ");
                }
                haji.setOffAlamat1(offAdd1.concat(offAdd2).concat(offAdd3));
                
                
                //haji.setOffAlamat1(resp.getTHOfficeAddress1().getValue().trim().concat(",").concat(" ").concat(resp.getTHOfficeAddress2().getValue().trim()).concat(",").concat(" ").concat(resp.getTHOfficeAddress3().getValue().trim()).concat(",").concat(" ").concat(resp.getTHOfficeAddress4().getValue().trim()));
                if(resp.getTHOfficePoskod().getValue()!=null){
                        Poskod poskod = poskodDAO.findById(resp.getTHOfficePoskod().getValue().trim());
                        haji.setOffPoskod( poskod.getPoskod());
                        haji.setOffCity(poskod.getNama());
                }
                haji.setOffFax(resp.getTHOfficeFax().getValue().trim());
                haji.setOffPhone(resp.getTHOfficePhone().getValue().trim());
                haji.setGroupRefNo(resp.getTHGroupRefNo().getValue().trim());
                haji.setTahunTawaran(resp.getTHHajYear().getValue().trim());
                haji.setTahunTawaranHijrah(resp.getTHHajYearI().getValue().trim());
                haji.setNoReg(resp.getTHRegNo().getValue().trim());
                haji.setNoPassport(resp.getTHPassportNo().getValue().trim());
                haji.setPakageCode(resp.getTHPackageCode().getValue().trim());
                haji.setHajiOfferStatus(resp.getTHHajOfferStatus().getValue().trim());
                haji.setHajiStatus(resp.getTHHajStatus().getValue().trim());
                haji.setTarikhTiba(format.parse(resp.getTHRetArrivalDate().getValue().trim()));
                haji.setRetCheckinPlace(resp.getTHRetCheckinPlace().getValue().trim());
                haji.setTarikhLaporDiriBalik(format.parse(resp.getTHRetCheckinDate().getValue().trim()));
                
                
                
                setHaji(haji); 
                
                SuratPenerbanganJH suratPenerbanganJH = new SuratPenerbanganJH();
                  suratPenerbanganJH.setAcctNo(haji.getNoAkaun());
                  suratPenerbanganJH.setAlamat1(haji.getAlamat1());
                  suratPenerbanganJH.setAlamat2(haji.getAlamat2());
                  suratPenerbanganJH.setAlamat3(haji.getAlamat3());
                  suratPenerbanganJH.setNama(haji.getNama());
                  suratPenerbanganJH.setNoKp(haji.getNoKp());
                  suratPenerbanganJH.setOrigin(haji.getCheckInPlace());
                  suratPenerbanganJH.setReturnDestination(haji.getLaporDiriBalik());
                  suratPenerbanganJH.setCheckInDate(haji.getTarikhPergi());
                  suratPenerbanganJH.setCheckOutDate(haji.getTarikhBalik());
               
                 // suratPenerbanganJH.setCheckInTime(haji.getMasaPergi());
                  suratPenerbanganJH.setCheckInTime(haji.getCheckInTimePhase1());
                  suratPenerbanganJH.setCheckOutTime(haji.getMasaBalik());
                  suratPenerbanganJH.setCheckInDay(haji.getCheckInDay());
                  suratPenerbanganJH.setFlightNo(haji.getNoPesawatPergi());
                  suratPenerbanganJH.setReturnFlightNo(haji.getNoPesawatBalik());
                  
                  String dest = haji.getDepFinal();
                  if (dest.equals("MD")) {
                      suratPenerbanganJH.setDestination("MADINAH");
                  } else if (dest.equals("MK")) {
                      suratPenerbanganJH.setDestination("MEKAH");
                  }
                  //suratPenerbanganJH.setDestination(haji.getDepFinal());
                  
                  suratPenerbanganJH.setAirportTo(haji.getRetFinal());
                  suratPenerbanganJH.setAirportFrom(haji.getRetCheckinPlace());
                  suratPenerbanganJH.setMiqat(haji.getMiqatDi());
                  suratPenerbanganJH.setTotaldays(haji.getJumlahHari());
                  suratPenerbanganJH.setOffAddress(haji.getOffAlamat1().concat(haji.getOffPoskod()).concat(", ").concat(haji.getOffCity()));
                  suratPenerbanganJH.setOffFax(haji.getOffFax());
                  suratPenerbanganJH.setOffPhone(haji.getOffPhone());
                  suratPenerbanganJH.setGroupNo(haji.getGroupRefNo());
                  suratPenerbanganJH.setPackageNo(haji.getPakageCode());
                  suratPenerbanganJH.setKtNo(haji.getNoKt());
                  suratPenerbanganJH.setNormalYear(haji.getTahunTawaran());
                  suratPenerbanganJH.setIslamicYear(haji.getTahunTawaranHijrah());
                  suratPenerbanganJH.setHajiOfferStatus(haji.getHajiOfferStatus());
                  suratPenerbanganJH.setHajiStatus(haji.getHajiStatus());
                  suratPenerbanganJH.setRegNo(haji.getNoReg());
                  suratPenerbanganJH.setPassportNo(haji.getNoPassport());
                  suratPenerbanganJH.setPoskod(haji.getPoskod());
                  suratPenerbanganJH.setNegeri(haji.getPoskodDeskripsi());
                  suratPenerbanganJH.setDateArrived(haji.getTarikhTiba());
                  suratPenerbanganJH.setTimeArrived(haji.getWaktuTiba());
                  suratPenerbanganJH.setRetCheckInDate(haji.getTarikhLaporDiriBalik());
                  //added in 08082014
                  if (haji.getCheckInDateMinus1() != null) {
                      suratPenerbanganJH.setCheckInDateMinus1(haji.getCheckInDateMinus1());
                  } else {
                      suratPenerbanganJH.setCheckInDateMinus1(" ");
                  }
                  
                  if (haji.getCheckInDayMinus1() != null) {
                      suratPenerbanganJH.setCheckInDayMinus1(haji.getCheckInDayMinus1());
                  } else {
                      suratPenerbanganJH.setCheckInDayMinus1(" ");
                  }
                  
                  if (haji.getAfterMidnite() != null) {
                  suratPenerbanganJH.setAfterMidnite(haji.getAfterMidnite());
                  } else {
                      suratPenerbanganJH.setAfterMidnite(" ");
                  }
                  
                  
                  String noKt = haji.getNoKt();
                  suratPenerbanganJH.setNoKT2(noKt.substring(2));
                  
                sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
                getContext().getRequest().getSession().setAttribute("SuratPenerbanganJH",suratPenerbanganJH);
                return new JSP("haji/jadual_penerbangan_detail.jsp");               
            }
            addSimpleError("" + responseManager.getResponseMessage(responseCode, FLT_SCH_MSG_ID));
        } catch (Exception ex) {            
            LOG.error(ex);
            responseCode = SYSTEM_ERROR;
            addSimpleError("" + responseManager.getResponseMessage(responseCode, FLT_SCH_MSG_ID));            
        } 
        sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
        return new JSP("haji/msg.jsp");
    }
    
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-SEMAK PENDAFTARAN HAJI-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    public Resolution showFormSemakPendaftaranHaji () {        
        pengguna = getContext().getCurrentUser();
        haji = new Haji();
        if (pengguna != null) {
            haji.setNoKp(pengguna.getNoKp());
        }   
        return new JSP("haji/pertanyaan_pendaftaran_haji.jsp");
    } 
    
    public Resolution semakPendaftaranHaji () {        
        String responseCode = "";
        DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");  
        
        
        
        try { // Call Web Service Operation
            com.oas.thit.hajj.services.HajjServices service = new com.oas.thit.hajj.services.HajjServices();
            com.oas.thit.hajj.services.HajjServicesPortType port = service.getHajjServicesHttpSoap11Endpoint();
            // TODO initialize WS operation arguments here
            com.oas.thit.hajj.hjcheck.xsd.HjCheckRequest req = new com.oas.thit.hajj.hjcheck.xsd.HjCheckRequest();
            
            com.oas.thit.hajj.hjcheck.xsd.ObjectFactory objFactory = new com.oas.thit.hajj.hjcheck.xsd.ObjectFactory();
            com.oas.thit.xmlmessage.xsd.ObjectFactory objHeader = new com.oas.thit.xmlmessage.xsd.ObjectFactory();
            Header reqHead = objHeader.createHeader();
            reqHead.setMsgId( objHeader.createHeaderMsgId(HAJ_CHK_MSG_ID));
            reqHead.setResponseCode( objHeader.createHeaderResponseCode(SUCCESSFUL) );            
            reqHead.setTxid(objHeader.createHeaderTxid( webUtil.getHeaderID(HAJ_CHK_MSG_ID, HEADER_ID_HAJ_REGISTRATION_CHECK) ));
           
            JAXBElement<Header> jReqHead = objHeader.createEventHeader(reqHead);
            req.setHeader(jReqHead); 

            HjCheckRequestBody reqBody = objFactory.createHjCheckRequestBody();
            reqBody.setTHAcct(objFactory.createHjCheckRequestBodyTHAcct(haji.getNoAkaun()));
            reqBody.setTHICNo(objFactory.createHjCheckRequestBodyTHICNo(haji.getNoKp()));
            
            JAXBElement<HjCheckRequestBody> jReqBody =  objFactory.createHjCheckRequestBody(reqBody);
            req.setBody(jReqBody);
            com.oas.thit.hajj.hjcheck.xsd.HjCheckResponse result = port.hjCheck(req);
            
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            if (responseCode.equals(SUCCESSFUL)) {
                HjCheckResponseBody resp = result.getBody().getValue();
                
                haji.setNoAkaun(resp.getTHAcct().getValue());
                haji.setNoRujukan(resp.getTHRefNo().getValue());
                haji.setNoDaftar(resp.getTHRegNo().getValue());
                haji.setNama(resp.getTHName().getValue());
                haji.setNoAkaun(resp.getTHAcct().getValue());
                haji.setNoKp(resp.getTHICNo().getValue());
                haji.setTahunPeruntukanHijrah(resp.getTHHajjYearI().getValue());
                haji.setTahunPeruntukan(resp.getTHHajjYear().getValue());
                haji.setPusatKosDeskripsi(resp.getTHOffice().getValue().trim());
                if(resp.getTHRegDate().getValue() != null)
                    haji.setTarikhDaftar(format.parse(resp.getTHRegDate().getValue().trim()));
                THISutil tHISutil = tHISutilDAO.findById("101");  
                haji.setNoTelTHCC(tHISutil.getDeskripsi().toString());
                setHaji(haji); 
                return new JSP("haji/pertanyaan_pendaftaran_haji_detail.jsp");
            }
            addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_CHK_MSG_ID));
            
        } catch (Exception ex) {
            LOG.error(ex);
            responseCode = SYSTEM_ERROR;
            addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_CHK_MSG_ID));
        }
        return new JSP("haji/msg.jsp");
    }
    
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-SURAT TAWARAN TUNAI HAJI-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    @AuthRequired
    public Resolution showSuratTawaranTunaiHaji (){
        haji = new Haji();
        pengguna = getContext().getCurrentUser();
        if (pengguna != null) {            
            haji.setNoKp(pengguna.getNoKp());
        } 
        return new JSP("haji/surat_tawaran_haji.jsp");
    }
     
    @AuthRequired
    public Resolution suratTawaranHaji () {
        pengguna = getContext().getCurrentUser();  
        String responseCode = "";
        DateFormat d = new SimpleDateFormat("yyyyMMdd"); 
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi(); 
        
        try {
            deposit = getProfileDeposit(haji.getNoAkaun(), haji.getNoKp());
        } catch (ParseException ex) {
            java.util.logging.Logger.getLogger(HajiActionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if (deposit != null) {
            
            AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
            deposit.setNoKpDari(haji.getNoKp());
            deposit.setNoAkaunDari(haji.getNoAkaun());
            boolean check = checking.checkAcc(deposit, pengguna);

            if (!check) {
                addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
            }
        } else {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
        }
        
        try {        
            com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
            com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap12Endpoint();
            // TODO initialize WS operation arguments here
            com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
            
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();          
            com.oas.thit.xmlmessage.xsd.ObjectFactory objHeader = new com.oas.thit.xmlmessage.xsd.ObjectFactory();
            Header reqHead = objHeader.createHeader();
            reqHead.setMsgId( objHeader.createHeaderMsgId(OFF_LTR_MSG_ID));
            reqHead.setResponseCode( objHeader.createHeaderResponseCode(SUCCESSFUL) );
            
            reqHead.setTxid(objHeader.createHeaderTxid( webUtil.getHeaderID(OFF_LTR_MSG_ID, HEADER_ID_HAJ_OFFER_LTR) ));
            
            JAXBElement<Header> jReqHead = objHeader.createEventHeader(reqHead);
            req.setHeader(jReqHead);            
            
            THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
            reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(haji.getNoAkaun()));
            reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(haji.getNoKp()));
            
            JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
            req.setBody(jReqBody); 
            // TODO process result here
            com.oas.thit._this.hajj.xsd.HajjOfferLetterResponse result = port.hajjOfferLetter(req);
            
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            
            sejarahTransaksi.setPengguna(pengguna);
            sejarahTransaksi.setTrhMasuk(new Date());
            sejarahTransaksi.setUrusan(kodUrusanDAO.findById(OFF_LTR_MSG_ID));
            sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
            sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
            sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
            
            if (responseCode.equals(SUCCESSFUL)) {
                HajjOfferLetterResponseBody resp = result.getBody().getValue();
                
                if(resp.getTHHajjStatus().getValue().trim().equals("")){
                List fieldList = resp.getRest();
                
                haji.setNama(resp.getTHName().getValue());
                haji.setNoAkaun(resp.getTHAcct().getValue());
                haji.setNoKp(resp.getTHICNo().getValue());
                haji.setTahunTawaran(resp.getTHYear().getValue());
                haji.setTahunTawaranHijrah(resp.getTHYearI().getValue());
                haji.setTarikhTawaran(d.parse(resp.getTHOfferDate().getValue().trim()));
                haji.setTarikhTutupTawaran(d.parse(resp.getTHCloseDate().getValue().trim()));
                haji.setStatusHaji(kodStatusHajiDAO.findById(resp.getTHHajjStatus().toString().trim()));                      
                haji.setPusatKos(pusatKosDAO.findById(resp.getTHOffice().getValue().toString().trim()));
                haji.setHajiOfferStatus(resp.getTHHajOfferStatus().getValue().trim());
                haji.setNoTelTHCC("03-62071919");
                
                haji.setAlamat1(getActionField("THAddress1",fieldList));
                haji.setAlamat2(getActionField("THAddress2",fieldList));
                haji.setAlamat3(getActionField("THAddress3",fieldList));
                String tHposkod = getActionField("THPoskod",fieldList);
                if(tHposkod !=null){
                        Poskod poskod = poskodDAO.findById(tHposkod);
                        haji.setPoskod( poskod.getPoskod());
                        haji.setPoskodDeskripsi(poskod.getNama());
                }                                                                                                                     
                haji.setOffAlamat1(getActionField("THOfficeAddress1",fieldList)+", "+getActionField("THOfficeAddress2",fieldList)+" ,"+getActionField("THOfficeAddress3",fieldList)+", "+getActionField("THOfficeAddress4",fieldList));
                haji.setOffFax(getActionField("THOfficeFax",fieldList));
                haji.setOffPhone(getActionField("THOfficePhone",fieldList));
                String tHoffposkod = getActionField("THOfficePoskod",fieldList);
                if(tHoffposkod!=null){
                        Poskod poskod = poskodDAO.findById(tHoffposkod);
                        haji.setOffPoskod( poskod.getPoskod());
                        haji.setOffCity(poskod.getNama());
                }
                
                haji.setNoReg(getActionField("THRegNo",fieldList));
                haji.setNoRef(getActionField("THRefNo",fieldList));                
                haji.setExpiryDate(d.parse(getActionField("THPMAValidity",fieldList)));
                haji.setCostMy1(new BigDecimal(getActionField("THHajCostMY1",fieldList)).multiply(new BigDecimal("0.01")));
                haji.setCostMy2(getActionField("THHajCostMY2",fieldList));
                haji.setCosrPr(new BigDecimal(getActionField("THHajCostPR",fieldList)).multiply(new BigDecimal("0.01")));
                haji.setSubsidyMy1(new BigDecimal(getActionField("THHajSubsidyMY1",fieldList)).multiply(new BigDecimal("0.01")));
                haji.setSubsidyMy2(getActionField("THHajSubsidyMY2",fieldList));
                haji.setSubsidyPr(new BigDecimal(getActionField("THHajSubsidyPR",fieldList)).multiply(new BigDecimal("0.01")));
                
                BigDecimal cm1 = new BigDecimal(getActionField("THHajCostMY1",fieldList)).multiply(new BigDecimal("0.01"));
                BigDecimal sb1 = new BigDecimal(getActionField("THHajSubsidyMY1",fieldList)).multiply(new BigDecimal("0.01"));
                BigDecimal b1 = cm1.add(sb1);
                
                haji.setBh1(b1);
                
                setHaji(haji);                 
                
                SuratTawaran suratTawaran = new SuratTawaran();
                  suratTawaran.setAlamat1(haji.getAlamat1());
                  suratTawaran.setAlamat2(haji.getAlamat2());
                  suratTawaran.setAlamat3(haji.getAlamat3());
                  suratTawaran.setNama(haji.getNama());
                  suratTawaran.setNoPengenalan(haji.getNoKp());
                  suratTawaran.setNoAkaun(haji.getNoAkaun());                 
                  suratTawaran.setPusatKos(haji.getPusatKos());
                  suratTawaran.setPoskod(haji.getPoskod());                 
                  suratTawaran.setTahunHijarah(haji.getTahunTawaranHijrah());
                  suratTawaran.setTahun(haji.getTahunTawaran());
                  suratTawaran.setBandar(haji.getPoskodDeskripsi());
                  suratTawaran.setTarikh(haji.getTarikhTawaran());
                  suratTawaran.setTarikhTutupTawaran(haji.getTarikhTutupTawaran());
                  suratTawaran.setNoPendaftaranHaji(haji.getNoReg());
                  suratTawaran.setOffAlamat1(haji.getOffAlamat1().concat(",").concat(" ").concat(haji.getOffPoskod()).concat(",").concat(" ").concat(haji.getOffCity()));
                  suratTawaran.setOffFax(haji.getOffFax());
                  suratTawaran.setOffPhone(haji.getOffPhone());
                  suratTawaran.setOffCity(haji.getOffCity());
                  suratTawaran.setBayaran1(haji.getBh1());
                  suratTawaran.setBayaran2(haji.getBh1());
                  suratTawaran.setBayaran3(haji.getCosrPr());
                  suratTawaran.setSubsidi1(haji.getSubsidyMy1());
                  suratTawaran.setSubsidi2(haji.getSubsidyMy2());
                  suratTawaran.setSubsidi3(haji.getSubsidyMy2());
                  suratTawaran.setBayaran1subsidi1(haji.getCostMy1());
                  suratTawaran.setBayaran2subsidi2(haji.getBh1());
                  suratTawaran.setBayaran3subsidi3(haji.getCosrPr());
                  suratTawaran.setTarikhLuput(haji.getExpiryDate());
                  suratTawaran.setHajiOfferStatus(haji.getHajiOfferStatus());
                  
                  sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
                getContext().getRequest().getSession().setAttribute("SuratTawaran",suratTawaran);
                return new JSP("haji/surat_tawaran_haji_detail.jsp");                
            
                }
                addSimpleMessage("TUAN / PUAN SUDAH MENJAWAB TAWARAN");
                return new JSP("haji/msg.jsp");                
               }
            
            
            //addSimpleError("" + responseManager.getResponseMessage(responseCode, OFF_LTR_MSG_ID)); 
            addSimpleMessage("" + responseManager.getResponseMessage(responseCode, OFF_LTR_MSG_ID)); 
        } catch (Exception ex) {
            LOG.error(ex);
            responseCode = SYSTEM_ERROR;
            addSimpleError("" + responseManager.getResponseMessage(responseCode, OFF_LTR_MSG_ID));        
        }         
        return new JSP("haji/msg.jsp");
    }
    
    public String getActionField(String fieldname, List arrayList1){
        for (int i = 0; i<=arrayList1.size(); i++){
            JAXBElement obj = (JAXBElement)arrayList1.get(i);
            if(obj.getName().getLocalPart()!=null && obj.getName().getLocalPart().trim().equals(fieldname)){
                if (obj.getValue()!= null)return obj.getValue().toString().trim();
                break;
            }
        }        
     return "";   
    }
    
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-CETAK SLIP PENDAFTARAN HAJI-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//    
    @AuthRequired
    public Resolution showCetakSlipPendaftaran () {
        pengguna = getContext().getCurrentUser();
        haji = new Haji();
        if (pengguna != null) {
            haji.setNoKp(pengguna.getNoKp());
        } 
        return new JSP("haji/cetak_slip_pendaftaran_haji.jsp");
    }
    
    @AuthRequired
    public Resolution showCetakSlipPendaftaranForm () {
        
        String responseCode = "";            
        SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy"); 
        SimpleDateFormat t = new SimpleDateFormat("hh:mm a");
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        
        try {
            deposit = getProfileDeposit(haji.getNoAkaun(), haji.getNoKp());
        } catch (ParseException ex) {
            java.util.logging.Logger.getLogger(HajiActionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if (deposit != null) {
            
            AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
            deposit.setNoKpDari(haji.getNoKp());
            deposit.setNoAkaunDari(haji.getNoAkaun());
            boolean check = checking.checkAcc(deposit, pengguna);

            if (!check) {
                addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
            }
        } else {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
                return new JSP("deposit/msg.jsp");
        }
        
            try { // Call Web Service Operation
                com.oas.thit.hajj.services.HajjServices service = new com.oas.thit.hajj.services.HajjServices();
                com.oas.thit.hajj.services.HajjServicesPortType port = service.getHajjServicesHttpSoap11Endpoint();
                // TODO initialize WS operation arguments here
                com.oas.thit.hajj.xsd.Request req = new com.oas.thit.hajj.xsd.Request();                
                
                com.oas.thit.hajj.xsd.ObjectFactory objFactory = new com.oas.thit.hajj.xsd.ObjectFactory();
                com.oas.thit.xmlmessage.xsd.ObjectFactory objHeader = new com.oas.thit.xmlmessage.xsd.ObjectFactory();
                Header reqHead = objHeader.createHeader();
                reqHead.setMsgId( objHeader.createHeaderMsgId(HAJ_SLIP_MSG_ID));
                reqHead.setResponseCode( objHeader.createHeaderResponseCode(SUCCESSFUL) );            
                reqHead.setTxid(objHeader.createHeaderTxid( webUtil.getHeaderID(HAJ_SLIP_MSG_ID, HEADER_ID_HAJ_SLIP_GROUP) ));
                
                JAXBElement<Header> jReqHead = objHeader.createEventHeader(reqHead);
                req.setHeader(jReqHead); 
                
                RequestBody reqBody = objFactory.createRequestBody();
                reqBody.setTHAccountNo(objFactory.createRequestBodyTHAccountNo(haji.getNoAkaun()));
                reqBody.setTHIcNo(objFactory.createRequestBodyTHIcNo(haji.getNoKp()));
                
                JAXBElement<RequestBody> jReqBody =  objFactory.createRequestBody(reqBody);
                req.setBody(jReqBody);
                
                // TODO process result here
                com.oas.thit.hajj.groupslip.xsd.GroupSlipResponse result = port.groupSlip(req);                
                Header header = result.getHeader().getValue();
                responseCode = header.getResponseCode().getValue();
                
                sejarahTransaksi.setPengguna(pengguna);
                sejarahTransaksi.setTrhMasuk(new Date());
                sejarahTransaksi.setUrusan(kodUrusanDAO.findById(HAJ_SLIP_MSG_ID));
                sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
                sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
                sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());                
                    if (responseCode.equals(SUCCESSFUL)) {
                        GroupSlipResponseBody resp = result.getBody().getValue();                        
                        if(resp.getTHHajRefNo().getValue().trim().equals("")){
                            haji.setNoRujukan("Tiada");
                        }else {
                            haji.setNoRujukan(resp.getTHHajRefNo().getValue());
                        }
                        haji.setTahunPeruntukan(resp.getTHHajjYear().getValue());
                        haji.setTahunPeruntukanHijrah(resp.getTHHajjYearI().getValue());
                        DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
                        if(resp.getTHRegDate().getValue() != null)
                            haji.setTarikhDaftar(format.parse(resp.getTHRegDate().getValue()));
                        haji.setNoTelTHCC(resp.getTHOfficePhone().getValue());
                        List<GroupSlipResponseLineItem> items  = resp.getLineItems();
                        List<SlipPendaftaran> senaraiAhli = new ArrayList<SlipPendaftaran>();
                        for ( GroupSlipResponseLineItem item : items ) {
                            SlipPendaftaran sp = new SlipPendaftaran();                        
                            sp.setNama(item.getTHName().getValue());
                            sp.setNoAkaun(item.getTHAcct().getValue());
                            sp.setNoDaftarHaji(item.getTHHajRegNo().getValue());
                            sp.setPejabatPengendali(item.getTHOffice().getValue());                        
                            senaraiAhli.add(sp);
                        }
                        haji.setSenaraiDaftarAhli(senaraiAhli);
                        sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
                        getContext().getRequest().getSession().setAttribute("haji", haji);                        
                        return new JSP("haji/cetak_slip_pendaftaran_haji_detail.jsp");
                    }
                    addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_SLIP_MSG_ID));            
                } 
                catch (Exception ex) {
                    LOG.error(ex);
                    responseCode = SYSTEM_ERROR;
                    addSimpleError("" + responseManager.getResponseMessage(responseCode, HAJ_SLIP_MSG_ID));
                }
            sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
            return new JSP("haji/msg.jsp");
    }   
    
    
    
    
    
    
     //-+-+-+-+-+-+-+-+-+-+-+-+-+-REPORTS-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//   
    
    //1)Registration Slip    
    public Resolution slipRegistration() throws Exception {        
      
      Haji haji = (Haji)getContext().getRequest().getSession().getAttribute("haji");
       /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("haji");
     
      SimpleDateFormat d = new SimpleDateFormat("d MMM yyyy"); 
      SimpleDateFormat t = new SimpleDateFormat("HH:mm:ss");
      
        List list = new ArrayList();
        List daftarAhliList =haji.getSenaraiDaftarAhli();
        if(daftarAhliList != null){             

             for(int i=0;i<daftarAhliList.size();i++){
                 HashMap submap = new HashMap();
                    SlipPendaftaran sp = (SlipPendaftaran)daftarAhliList.get(i);
                    submap.put("s_Name",sp.getNama());
                    submap.put("s_Account no", sp.getNoAkaun());
                    submap.put("s_Registration no", sp.getNoDaftarHaji());
                    submap.put("s_Cost-Centre", sp.getPejabatPengendali());
                    list.add(submap);
            }
         }
       
        HashMap slipmap = new HashMap();
        slipmap.put("s_list", list);
        //slipmap.put("name", haji.getNama());
        if(haji.getNoRujukan() == null || haji.getNoRujukan().trim().equals("")){
            slipmap.put("Ref no", "Tiada");
        }else {
            slipmap.put("Ref no", haji.getNoRujukan());
        }
        slipmap.put("Islamic Year", haji.getTahunPeruntukanHijrah());
        slipmap.put("Normal Year", haji.getTahunPeruntukan());
        
        String simpledt = d.format(haji.getTarikhDaftar());
        String simpletm = t.format(haji.getTarikhDaftar());
        
        slipmap.put("Registration Date", simpledt);
        slipmap.put("Registration Time", simpletm);
        slipmap.put("Tel no", haji.getNoTelTHCC());
        String reportpath = conf.getProperty("report.path");
        slipmap.put("SUBREPORT_DIR", reportpath); 
        slipmap.put("REPORT_DIR", reportpath);
       
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"SLIPPENDAFTARANHAJI.jasper", slipmap, new JREmptyDataSource());
        final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
         InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
        
//        return new StreamingResolution("application/pdf") {
//        @Override
//            public void stream(HttpServletResponse response) throws Exception {
//                response.setHeader("Cache-Control", "no-cache");
//                response.setHeader("Pragma", "no-cache");
//                response.setDateHeader("Expires", 0);
//                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//                ServletOutputStream out = response.getOutputStream();
//                out.write(bytes);
//                out.flush();
//                out.close(); 
//            } 
//        };
        
//        return new StreamingResolution("application/pdf") {
//
//            @Override
//            public void stream(HttpServletResponse response) throws Exception {
////                response.setHeader("Cache-Control", "no-cache");
////                response.setHeader("Pragma", "no-cache");
////                response.setDateHeader("Expires", 0);
////                response.setContentType("application/pdf");
////                response.setHeader("Content-disposition", "inline; filename=test.pdf");
////                ServletOutputStream out = response.getOutputStream();
////                out.write(bytes);
////                out.flush();
////                out.close();
//                InputStream inputStream = new ByteArrayInputStream(bytes);
//                BufferedInputStream bis = new BufferedInputStream(inputStream);
//                ByteArrayOutputStream bous = new ByteArrayOutputStream();
//                
//                int ch;
//                while ((ch = bis.read()) != -1) {
//                    bous.write(ch);
//                }
//                bous.writeTo(response.getOutputStream());
//            }
//        }.setFilename("slip_pendaftaran_haji");
     }
    
    //2)Offer Letter
    
   public Resolution surat() throws Exception{   
        
    
        SuratTawaran st = (SuratTawaran)getContext().getRequest().getSession().getAttribute("SuratTawaran");
        /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("SuratTawaran");
        
            SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
      
            HashMap map = new HashMap();                                   
             
             map.put("Account no", st.getNoAkaun());
             map.put("name", st.getNama());
             map.put("IC no", st.getNoPengenalan());             
             map.put("Registration no", st.getNoPendaftaranHaji());
             map.put("Islamic Year", st.getTahunHijarah());
             map.put("Normal Year", st.getTahun());
             map.put("Address-line1", st.getAlamat1());
             map.put("Address-line2", st.getAlamat2());
             map.put("Address-line3", st.getAlamat3());
             map.put("Post Code", st.getPoskod());
             map.put("City", st.getBandar());
             map.put("Ref no", st.getNoRef());
             String tarikhdt = d.format(st.getTarikh());
             map.put("Date", tarikhdt);
             map.put("Cost-Centre", st.getPusatKos().getKod());
             map.put("Cost-Centre-Description", st.getPusatKos().getNama());
             String closingdt = d.format(st.getTarikhTutupTawaran());
             map.put("Closing-Date", closingdt);
             map.put("Fee1", st.getBayaran1());
             map.put("Fee2", st.getBayaran2());
             map.put("Fee3", st.getBayaran3());
             map.put("Subsidy1", st.getSubsidi1());
             map.put("Subsidy2", st.getSubsidi2());
             map.put("Subsidy3", st.getSubsidi3());
             map.put("(Fee1-Subsidy1)", st.getBayaran1subsidi1());
             map.put("(Fee2-Subsidy2)", st.getBayaran2subsidi2());
             map.put("(Fee3-Subsidy3)", st.getBayaran3subsidi3()); 
             String expirydt = d.format(st.getTarikhLuput());
             map.put("Expiry-Date", expirydt);
             map.put("Office Address1", st.getOffAlamat1());
             map.put("Office Fax", st.getOffFax());
             map.put("Office Phone", st.getOffPhone());
              
            String reportpath = conf.getProperty("report.path");
            map.put("REPORT_DIR", reportpath);
            if(st.getHajiOfferStatus().trim().equals("P101")){
            JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP1.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint2 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP2.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint3 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP3.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint4 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP4.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint5 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP5.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint6 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP6.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint7 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP7.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint8 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP8.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint9 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP9.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint10 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP10.jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint11 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP11.jasper", map, new JREmptyDataSource());
            jasperPrint1.addPage(jasperPrint2.getPages().get(0));
            jasperPrint1.addPage(jasperPrint3.getPages().get(0));
            jasperPrint1.addPage(jasperPrint4.getPages().get(0));
            jasperPrint1.addPage(jasperPrint5.getPages().get(0));
            jasperPrint1.addPage(jasperPrint6.getPages().get(0));
            jasperPrint1.addPage(jasperPrint7.getPages().get(0));
            jasperPrint1.addPage(jasperPrint8.getPages().get(0));
            jasperPrint1.addPage(jasperPrint9.getPages().get(0));
            jasperPrint1.addPage(jasperPrint10.getPages().get(0));
            jasperPrint1.addPage(jasperPrint11.getPages().get(0));
 
            final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
            
             InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);

//            return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_tawaran_haji");
            
            }
            else if(st.getHajiOfferStatus().trim().equals("P104")){
            JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(1).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint2 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(2).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint3 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(3).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint4 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(4).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint5 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(5).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint6 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(6).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint7 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(7).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint8 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP104(8).jasper", map, new JREmptyDataSource());
            jasperPrint1.addPage(jasperPrint2.getPages().get(0));
            jasperPrint1.addPage(jasperPrint3.getPages().get(0));
            jasperPrint1.addPage(jasperPrint4.getPages().get(0));
            jasperPrint1.addPage(jasperPrint5.getPages().get(0));
            jasperPrint1.addPage(jasperPrint6.getPages().get(0));
            jasperPrint1.addPage(jasperPrint7.getPages().get(0));
            jasperPrint1.addPage(jasperPrint8.getPages().get(0));
 
            final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
             InputStream is = new ByteArrayInputStream(bytes);
           return new StreamingResolution("application/pdf", is);
//            return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_tawaran_haji");
            
            }
            else if(st.getHajiOfferStatus().trim().equals("P110")){
            JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(1).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint2 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(2).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint3 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(3).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint4 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(4).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint5 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(5).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint6 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(6).jasper", map, new JREmptyDataSource());
            JasperPrint jasperPrint7 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP110(7).jasper", map, new JREmptyDataSource());
            jasperPrint1.addPage(jasperPrint2.getPages().get(0));
            jasperPrint1.addPage(jasperPrint3.getPages().get(0));
            jasperPrint1.addPage(jasperPrint4.getPages().get(0));
            jasperPrint1.addPage(jasperPrint5.getPages().get(0));
            jasperPrint1.addPage(jasperPrint6.getPages().get(0));
            jasperPrint1.addPage(jasperPrint7.getPages().get(0));
 
            final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
             InputStream is = new ByteArrayInputStream(bytes);
            return new StreamingResolution("application/pdf", is);
//            return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_tawaran_haji");
            
            }
        return new StreamingResolution("application/pdf");
    }   
    
    //3)Offer Acceptance - didn't use
      public Resolution accept() throws Exception {
          
      SuratTawaran st = (SuratTawaran)getContext().getRequest().getSession().getAttribute("st");
      /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("st");
      
         HashMap map = new HashMap();
              map.put("name", st.getNama());
              map.put("Address-line1", st.getAlamat1());
              map.put("Address-line2", st.getAlamat2());
              map.put("Post Code", st.getPoskod());
              map.put("City", st.getBandar());
              map.put("Account no", st.getNoAkaun());
              map.put("Registration no", st.getNoPendaftaranHaji());       
              map.put("Islamic Year", st.getTahunHijarah());
              map.put("Normal Year", st.getTahun());
              map.put("Closing-Date", st.getTarikhTutupTawaran());
           
            String reportpath = conf.getProperty("report.path");
          JasperPrint jasperPrint3 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP3.jasper", map, new JREmptyDataSource());
          JasperPrint jasperPrint4 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP4.jasper", map, new JREmptyDataSource());
          JasperPrint jasperPrint5 = JasperFillManager.fillReport(reportpath+"SURATTAWARANP5.jasper", map, new JREmptyDataSource());
          jasperPrint3.addPage(jasperPrint4.getPages().get(0));
          jasperPrint3.addPage(jasperPrint5.getPages().get(0));
          
       final byte[] bytes=JasperExportManager.exportReportToPdf(jasperPrint3);
        InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
//     return new StreamingResolution("application/pdf"){
//       @Override
//            public void stream(HttpServletResponse response) throws Exception {
//                response.setHeader("Cache-Control", "no-cache");
//                response.setHeader("Pragma", "no-cache");
//                response.setDateHeader("Expires", 0);
//                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//                ServletOutputStream out = response.getOutputStream();
//                out.write(bytes);
//                out.flush();
//                out.close();
//     
//     }
//     };
     }
      
     //3a)Offer Acceptance II added in - 22/04/13
      public Resolution acceptOffer() throws Exception {
          
      SuratTawaran st = (SuratTawaran)getContext().getRequest().getSession().getAttribute("SuratTawaran");
      /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("SuratTawaran");
      
        //check the value back, what to display in report
         HashMap map = new HashMap();
              map.put("name", st.getNama());
              map.put("Address-line1", st.getAlamat1());
              map.put("Address-line2", st.getAlamat2());
              map.put("Address-line3", st.getAlamat3());
              map.put("Post Code", st.getPoskod());
              map.put("City", st.getBandar());
              map.put("Account no", st.getNoAkaun());
              map.put("Registration no", st.getNoPendaftaranHaji());       
              map.put("Islamic Year", st.getTahunHijarah());
              map.put("Normal Year", st.getTahun());
             // map.put("Closing-Date", st.getTarikhTutupTawaran());
        
        String reportpath = conf.getProperty("report.path");
        map.put("REPORT_DIR", reportpath);
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"acceptOffer.jasper", map, new JREmptyDataSource());
        //new add 9 Dec 2013
        JasperPrint mahram1 = JasperFillManager.fillReport(reportpath+"keperluanMahram_pg1.jasper", map, new JREmptyDataSource());
        JasperPrint mahram2 = JasperFillManager.fillReport(reportpath+"keperluanMahram_pg2.jasper", map, new JREmptyDataSource());
        JasperPrint mahram3 = JasperFillManager.fillReport(reportpath+"keperluanMahram_pg3.jasper", map, new JREmptyDataSource());
        
        jasperPrint1.addPage(mahram1.getPages().get(0));
        jasperPrint1.addPage(mahram2.getPages().get(0));
        jasperPrint1.addPage(mahram3.getPages().get(0));
        
       final byte[] bytes=JasperExportManager.exportReportToPdf(jasperPrint1);
        InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
//       return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_terima _tawaran_haji");
     }
     
    
    //4) Offer Decline
          
     public Resolution decline() throws Exception {
          
      SuratTawaran st = (SuratTawaran)getContext().getRequest().getSession().getAttribute("SuratTawaran");
      /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("SuratTawaran");
      
          
        HashMap map = new HashMap();
              map.put("name", st.getNama());
              map.put("Address-line1", st.getAlamat1());
              map.put("Address-line2", st.getAlamat2());
              map.put("Post Code", st.getPoskod());
              map.put("City", st.getBandar());
              map.put("Account no", st.getNoAkaun());
              map.put("Registration no", st.getNoPendaftaranHaji());       
              map.put("Islamic Year", st.getTahunHijarah());
              map.put("Normal Year", st.getTahun());
             
             String reportpath = conf.getProperty("report.path");
              map.put("REPORT_DIR", reportpath);
             
          JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"Decline.jasper", map, new JREmptyDataSource());
     
          final byte[] bytes=JasperExportManager.exportReportToPdf(jasperPrint1);
           InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
//        return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_menolak_tawaran_haji");
  }
          
          
    
    //5)Tanggungan Haji
         
    public Resolution tanggunan() throws Exception{
         
            
      Haji haji = (Haji)getContext().getRequest().getSession().getAttribute("haji");
      /**
       * comment to make cetak works in IE
       */
      //getContext().getRequest().getSession().removeAttribute("haji");
      
      SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
      
        HashMap map = new HashMap();
              map.put("name", haji.getNama());
              map.put("Account no", haji.getNoAkaun());
              map.put("Registration no", haji.getNoReg());       
              map.put("Islamic Year", haji.getTahunTawaranHijrah());
              map.put("Normal Year", haji.getTahunTawaran());
              map.put("IC no", haji.getNoKp());
              
              String decdt = d.format(haji.getTarikhTolakTanggunganHaji()); 
              map.put("Decline Date", decdt);
              
            String reportpath = conf.getProperty("report.path");
                map.put("REPORT_DIR", reportpath);
          JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"Tanggungan.jasper", map, new JREmptyDataSource());
          
          
       final byte[] bytes=JasperExportManager.exportReportToPdf(jasperPrint1);
        InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
//       return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_menolak_tanggungan_haji"); 
     }
          
      
    
    //6)Flight Schedule
      public Resolution SuratPenerbangan() throws Exception{
            
            SuratPenerbanganJH spj = (SuratPenerbanganJH)getContext().getRequest().getSession().getAttribute("SuratPenerbanganJH");
            /**
            * comment to make cetak works in IE
            */
           //getContext().getRequest().getSession().removeAttribute("SuratPenerbanganJH");

            SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
                HashMap map = new HashMap();
                
                map.put("noKp",spj.getNoKp());
                map.put("barcode", spj.getBarCode());
                map.put("name", spj.getNama());
                map.put("address1", spj.getAlamat1());
                map.put("address2", spj.getAlamat2());
                map.put("address3", spj.getAlamat3());
                map.put("postcode", spj.getPoskod());
                map.put("statecode", spj.getNegeri());
                
                String dt = d.format(new Date());
                map.put("date", dt);
                map.put("reg_no", spj.getRegNo());
                map.put("passport_no", spj.getPassportNo());
                map.put("i/c_no", spj.getNoKp());
                map.put("group_no", spj.getGroupNo());
                map.put("package_no",spj.getPackageNo());
                map.put("kt_no", spj.getKtNo());
                map.put("origin", spj.getOrigin());
                map.put("origin2", spj.getOrigin2());
                map.put("origin3", spj.getOrigin3());
                map.put("airport_from", spj.getAirportFrom());
                map.put("airport_from2", spj.getAirportFrom2());
                
                String indt = d.format(spj.getCheckInDate());
                map.put("check_in_date", indt);
                map.put("check_in_time", spj.getCheckInTime());
                map.put("check_in_day", spj.getCheckInDay());
                
                String outdt = d.format(spj.getCheckOutDate());
                map.put("check_out_date", outdt);
                map.put("check_out_time", spj.getCheckOutTime());
                map.put("flight_no", spj.getFlightNo());
                map.put("return_flight_no", spj.getReturnFlightNo());
                map.put("totaldays", spj.getTotaldays());
                map.put("destination", spj.getDestination());
                map.put("miqat",spj.getMiqat());
                
                String dtarr = d.format(spj.getDateArrived());
                map.put("date_arrived", dtarr);
                map.put("airport_to", spj.getAirportTo());
                map.put("time_arrived", spj.getTimeArrived());
                map.put("acct_no", spj.getAcctNo());
                map.put("Office Address", spj.getOffAddress());
                map.put("Office Phone", spj.getOffPhone());
                map.put("Office Fax", spj.getOffFax());
                map.put("Haji OfferStatus", spj.getHajiOfferStatus());
                map.put("Haji Status", spj.getHajiStatus());
                map.put("Islamic Year", spj.getIslamicYear());
                map.put("Normal Year", spj.getNormalYear());
                map.put("ktNoSub", spj.getKtNo2());
                map.put("RetDest", spj.getReturnDestination());
                String date = d.format(spj.getRetCheckInDate());
                map.put("retCheckInDate", date);
               
                //added in 08082014
                map.put("checkInDateMinus1", spj.getCheckInDateMinus1());
                map.put("checkInDayMinus1", spj.getCheckInDayMinus1());
                map.put("afterMidnite", spj.getAfterMidnite());
            
            String reportpath = conf.getProperty("report.path");
            map.put("REPORT_DIR", reportpath);
            JasperPrint jasperPrint = JasperFillManager.fillReport(reportpath+"SuratPenerbanganJH.jasper", map,new JREmptyDataSource());
           
            JasperPrint spJP = JasperFillManager.fillReport(reportpath+"SuratPenerbanganJH_Sub1.jasper", map, new JREmptyDataSource());
            //Surat Dam & Qurban : 15 Aug 2013
            JasperPrint spDam = JasperFillManager.fillReport(reportpath+"SuratPenerbanganJH_Sub2.jasper", map, new JREmptyDataSource());
            jasperPrint.addPage(spJP.getPages().get(0));
            jasperPrint.addPage(spDam.getPages().get(0));
            
           
           final byte[]  bytes = JasperExportManager.exportReportToPdf(jasperPrint);
            InputStream is = new ByteArrayInputStream(bytes);
        return new StreamingResolution("application/pdf", is);
//        return new StreamingResolution("application/pdf") {
//
//                @Override
//                public void stream(HttpServletResponse response) throws Exception {
//    //                response.setHeader("Cache-Control", "no-cache");
//    //                response.setHeader("Pragma", "no-cache");
//    //                response.setDateHeader("Expires", 0);
//    //                response.setContentType("application/pdf");
//    //                response.setHeader("Content-disposition", "inline; filename=test.pdf");
//    //                ServletOutputStream out = response.getOutputStream();
//    //                out.write(bytes);
//    //                out.flush();
//    //                out.close();
//                    InputStream inputStream = new ByteArrayInputStream(bytes);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
//
//                    int ch;
//                    while ((ch = bis.read()) != -1) {
//                        bous.write(ch);
//                    }
//                    bous.writeTo(response.getOutputStream());
//                }
//            }.setFilename("surat_penerbangan");
    }
    //    

      
      
    /**
     * Get profile from deposit
     * @param noAkaun
     * @param noKP
     * @return 
     * 
     */
    public Deposit getProfileDeposit(String noAkaun, String noKP) throws ParseException {
       
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        String responseCode = "";
        //Deposit deposit = null;
        
        com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
        com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap11Endpoint();
        com.oas.thit._this.xsd.THISRequest reqDeposit = new com.oas.thit._this.xsd.THISRequest();
        com.oas.thit._this.xsd.ObjectFactory objFactoryDeposit = new com.oas.thit._this.xsd.ObjectFactory();
        reqDeposit.setHeader( webUtil.createHeader(PROFILE_ENQ_MSG_ID, HEADER_ID_PROFILE_ENQUIRY) );
        THISBaseDataElementBody reqBodyDeposit = objFactoryDeposit.createTHISBaseDataElementBody();
        
        reqBodyDeposit.setTHAcct(objFactoryDeposit.createTHISBaseDataElementBodyTHAcct(noAkaun));
        reqBodyDeposit.setTHICNo(objFactoryDeposit.createTHISBaseDataElementBodyTHICNo(noKP));

        JAXBElement<THISBaseDataElementBody> jReqBodyDeposit =  objFactoryDeposit.createTHISRequestBody(reqBodyDeposit);
        reqDeposit.setBody(jReqBodyDeposit);
        
         /*
          * Query for deposit : profile
          */
            com.oas.thit._this.profile.depositor.xsd.DepositorProfileResponse resultDeposit = port.depositorProfileQuery(reqDeposit);
            Header headerDeposit = resultDeposit.getHeader().getValue();
            responseCode = headerDeposit.getResponseCode().getValue();
            if (responseCode.equals(SUCCESSFUL)) {
                 DepositorProfileResponseBody respDeposit = resultDeposit.getBody().getValue();
                 if (respDeposit != null) { 
                    deposit = new Deposit();
                    deposit.setAlamat1(respDeposit.getTHAddress1().getValue());
                    deposit.setAlamat2(respDeposit.getTHAddress2().getValue());
                    deposit.setAlamat3(respDeposit.getTHAddress3().getValue());
                    deposit.setBangsa(respDeposit.getTHEthnic().getValue());
                    deposit.setEmail(respDeposit.getTHemail().getValue());
                    deposit.setNoAkaun(respDeposit.getTHAcct().getValue().trim());
                    deposit.setNoBuku(respDeposit.getTHPassbookNo().getValue());
                    deposit.setNoKp(respDeposit.getTHICNo().getValue().trim());
                    deposit.setNoTel1(respDeposit.getTHPhoneHome().getValue());
                    deposit.setNoTel2(respDeposit.getTHPhoneMobile().getValue());
                    deposit.setNoTel3(respDeposit.getTHPhoneOffice().getValue());
                    deposit.setPoskod(respDeposit.getTHPoskod().getValue());
                    deposit.setNama(respDeposit.getTHName().getValue());
                    
                    if (respDeposit.getTHGender() != null) {
                        deposit.setJantina(kodJantinaDAO.findById(respDeposit.getTHGender().getValue().trim()));
                    }
                    if  (respDeposit.getTHMarital() != null) {
                        deposit.setKahwin(kodKahwinDAO.findById(respDeposit.getTHMarital().getValue().trim()));
                    }
                   
                    if (respDeposit.getTHState() != null) {
                        deposit.setNegeri(kodNegeriDAO.findById(respDeposit.getTHState().getValue().trim()));
                    }
                     if (respDeposit.getTHEmploy() != null) {
                        deposit.setPekerjaan(kodPekerjaanDAO.findById(respDeposit.getTHEmploy().getValue().trim()));
                    }
                    if (respDeposit.getTHNationality() != null) {
                        deposit.setWarganegara(kodWarganegaraDAO.findById(respDeposit.getTHNationality().getValue().trim()));
                    }
                    
                    /*
                     * Set date
                     */
                    String df = new DateFormatDetector().getDateFormat(respDeposit.getTHDOB().getValue());
                    sdf = new SimpleDateFormat(df);
                    deposit.setTarikhLahir(sdf.parse(respDeposit.getTHDOB().getValue()));
                    
                 }
            }
        return deposit;
    }
    
    
    public Pengguna getPengguna() {
        return pengguna;
    }

    public void setPengguna(Pengguna pengguna) {
        this.pengguna = pengguna;
    }

    public Haji getHaji() {
        return haji;
    }

    public void setHaji(Haji haji) {
        this.haji = haji;
    }

    public Kumpulan getKumpulan() {
        return kumpulan;
    }

    public void setKumpulan(Kumpulan kumpulan) {
        this.kumpulan = kumpulan;
    }

    
  
}
